package net.oschina.app.adapter.tweetsadapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Tweet;
import net.oschina.app.util.UIUtils;
import net.oschina.app.view.CircleImageView;

import java.util.List;

/**
 * Created by ldl on 2017/4/2.
 */

public class TweetsListAdapter extends BaseRecyclerViewAdapter {
    public List<Tweet> datas;

    public TweetsListAdapter(List<Tweet> datas) {
        this.datas = datas;
    }

    @Override
    public TweetsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // 充气条目到主要列表
        View view = mInflater.inflate(R.layout.base_tweets_item, parent, false);
        TweetsViewHolder tvh = new TweetsViewHolder(view);
        return tvh;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TweetsViewHolder holder1 = (TweetsViewHolder) holder;
        Tweet tweet = datas.get(position);
        //  通过URL获取头像，图片框架Glide
        if(!"".equals(tweet.getPortrait())) {
            Glide.with(UIUtils.getContext()).load(tweet.getPortrait()).override(UIUtils.dip2Px(50), UIUtils.dip2Px(50)).into(holder1.mCivPortrait);
        }
        holder1.mTvAuthor.setText(tweet.getAuthor());
        holder1.mTvBody.setText(tweet.getBody());
        holder1.mTvPubDate.setText(tweet.getPubDate());
        holder1.mTvAppclient.setText(tweet.getAppclient()+"");
//        holder1.mTvIsLike.setText(tweet.getIsLike()+"");
        holder1.mTvCommentCount.setText(tweet.getCommentCount());
        // 觉得很赞应该怎么弄
        holder1.mTvZanPerson.setText(tweet.getAuthor());
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class TweetsViewHolder extends XRecyclerView.ViewHolder {
        public CircleImageView mCivPortrait;
        public TextView mTvAuthor;
        public TextView mTvBody;
        public TextView mTvPubDate;
        public TextView mTvAppclient;
        public ImageView mTvIsLike;
        public TextView mTvCommentCount;
        public TextView mTvZanPerson;

        public TweetsViewHolder(View itemView) {
            super(itemView);
            mCivPortrait = (CircleImageView) itemView.findViewById(R.id.dd_civ_portrait);
            mTvAuthor = (TextView) itemView.findViewById(R.id.dd_tv_author);
            mTvBody = (TextView) itemView.findViewById(R.id.dd_tv_body);
            mTvPubDate = (TextView) itemView.findViewById(R.id.dd_tv_pubDate);
            mTvAppclient = (TextView) itemView.findViewById(R.id.dd_tv_appclient);
            mTvIsLike = (ImageView) itemView.findViewById(R.id.dd_tv_isLike);
            mTvCommentCount = (TextView) itemView.findViewById(R.id.dd_tv_commentCount);
            mTvZanPerson = (TextView) itemView.findViewById(R.id.dd_tv_zan_person);
        }
    }
}